import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import requireTransform from 'vite-plugin-require-transform'
import { PrimeVueResolver } from '@primevue/auto-import-resolver'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  minify: true,
  plugins: [
    vue(),
    Components({
      resolvers: [PrimeVueResolver()],
    }),
    requireTransform({
      fileRegex: /.js$|.vue$|.png$|.ts$|.jpg$|.svg$/,
    }),
  ],
  resolve: {
    alias: {
      '~': path.resolve(__dirname, './'),
      '@': path.resolve(__dirname, './src'),
    },
    extensions: ['.vue', '.js', '.mjs', '.ts'],
  },
  server: {
    port: 8080,
    proxy: {
      '/api': {
        target: 'http://172.16.8.29:20108',
        changeOrigin: false,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      '/oauth2/consent': {
        target: 'http://127.0.0.1:8888',
        changeOrigin: false,
      },
    },
  },
})
